home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / -serious- / comms / other / novia / src / novia_myget.c < prev    next >
Text File  |  1999-12-06  |  6KB  |  271 lines

  1. #include <exec/types.h>
  2. //#include <exec/memory.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <stdio.h>
  6. #include <ctype.h>
  7. #include <pragma/noviasys_lib.h>
  8. #include <novia/novia_portdata.h>
  9.  
  10. char editfield(char *bp, char *src, char maxlen, char fieldlen, ULONG flags, ULONG sigs)
  11. {
  12.     struct PortData *cport=(PortData *)FindTask(NULL)->tc_UserData;
  13.     char result = 0;
  14.     Writeio("",-1);
  15.     if (cport)
  16.     {
  17.         char cp[80];
  18.         char bp2[80];
  19.         char pos        = 0;
  20.         char end        = 0;
  21.         char start    = 0;
  22.         BOOL Quit    = FALSE;
  23.         BOOL habschon;
  24.         BOOL change    = FALSE;
  25.         int i;
  26.         char wert;
  27.         short counter;
  28.         BOOL first    = FALSE;
  29.         BOOL ende    = FALSE;
  30.         *bp            = 0;
  31.         Writeio("c3",-1);
  32.         if (src!=0)
  33.         {
  34.             strcpy(bp,src);
  35.             end = strlen(bp);
  36.             if (end > fieldlen)
  37.             {
  38.                 Writeio(bp + (end - fieldlen),fieldlen);
  39.                 start = end - fieldlen;
  40.             }
  41.             else
  42.             {
  43.                 Writeio(bp, fieldlen);
  44.             }
  45.             pos = end;
  46.         }
  47.         
  48. //        printf("pos: %d start: %d end: %d maxlen: %d fieldlen: %d source: <%s>\n",pos,start,end,maxlen,fieldlen,src);
  49.  
  50.         bp[end]=0;
  51.         while(!Quit && cport->network.online)
  52.         {
  53. //            printf("pos: %d start: %d end: %d pos: <%c>\n",pos,start,end,bp[pos]);
  54.             habschon=FALSE;
  55.             Conread(cp,1,sigs);
  56.             if (*cp==13)
  57.             {
  58.                 *cp=10;
  59.                 Writeio(cp,1);
  60.                 Quit=TRUE;
  61.             }
  62.             if (*cp==-101)
  63.             {
  64.                 Conread(cp,1,sigs);
  65.                 switch (*cp)
  66.                 {
  67.                     case 'D':            // CURSER LEFT
  68.                         if (pos>0)
  69.                         {
  70.                             if (pos - start > 0)
  71.                             {
  72.                                 Writeio("D",-1);
  73.                             }
  74.                             else
  75.                             {
  76.                                 start--;
  77.                                 if ((end - pos) > fieldlen)
  78.                                 {
  79. //                                    printf("CURSER LEFT: end - pos <= fieldlen, %d %d\n",end,pos);
  80.                                     Writeio(bp + start,fieldlen);
  81.                                     cleft(fieldlen);
  82.                                 }
  83.                                 else
  84.                                 {
  85. //                                    printf("CURSER LEFT: end - pos %d %d\n",end,pos);
  86.                                     Writeio(bp + start, end - pos);
  87.                                     cleft(end - pos);
  88.                                 }
  89.                             }
  90.                             pos--;
  91.                          }
  92.                         break;
  93.                     case 'C':            // CURSER RIGHT
  94.                         if (pos<end && end<=maxlen)
  95.                         {
  96.                             if (pos - start < fieldlen)
  97.                             {
  98.                                 Writeio("C",-1);
  99.                             }
  100.                             else
  101.                             {
  102.                                 start++;
  103.                                 cleft(fieldlen);
  104.                                 Writeio(bp + start,fieldlen);
  105.                             }
  106.                             pos++;
  107.                         }
  108.                         break;
  109.                 }
  110.                 habschon=TRUE;
  111.                 change=TRUE;
  112.             }
  113.             if (*cp == 8 && habschon == FALSE)        // BACKSPACE
  114.             {
  115.                 if (pos > 0)
  116.                 {
  117. //                    printf("BACKSPACE\n");
  118.                     if (start < pos)
  119.                     {
  120.                         cleft(1);
  121.                         if (end - pos >= fieldlen)
  122.                         {
  123.                             Writeio(bp + pos, (fieldlen - (pos - start)) + 1);
  124.                             cleft((fieldlen - (pos - start)) + 1);
  125.                         }
  126.                         else
  127.                         {
  128. //                            printf("start == pos %d %d\n",start,pos);
  129.                             Writeio(bp + pos, end - pos);
  130.                             space(fieldlen - (end - pos) - (pos - start) + 1);
  131.                             cleft(fieldlen - (end - pos) - (pos - start) + 1);
  132.                             cleft(end - pos);
  133.                         }
  134.                     }
  135.                     else
  136.                     {
  137.                         start--;
  138.                     }
  139.                     pos--;
  140.                     for (i=pos;i<end;i++)
  141.                     {
  142.                         bp[i]=bp[i+1];
  143.                     }
  144.                     end--;
  145.                     change = TRUE;
  146.                 }
  147.                 habschon = TRUE;
  148.             }
  149.             if (*cp == 127 &&habschon == FALSE)    // DELete
  150.             {
  151.                 if (pos < end)
  152.                 {
  153.                     for (i=pos;i<end;i++)
  154.                     {
  155.                         bp[i]=bp[i+1];
  156.                     }
  157.                     end--;
  158.                     Writeio(bp + pos, fieldlen - (pos - start));
  159.                     if (end - pos > fieldlen)
  160.                     {
  161.                         cleft((fieldlen - (pos - start)));
  162.                     }
  163.                     else
  164.                     {
  165.                         space(fieldlen - (pos - start) - (end - pos));
  166.                         cleft(fieldlen - (pos - start) - (end - pos));
  167.                         cleft(end - pos);
  168.                     }
  169.                     change = TRUE;
  170.                 }
  171.                 habschon = TRUE;
  172.             }
  173.             if (((*cp>=-96 && *cp<0) | (*cp>=32 && *cp<127)) && end<maxlen && pos<maxlen && habschon==FALSE)
  174.             {
  175.                 if ((!(flags & INPUT_TYPE_NUMBER))| (*cp>47 && *cp<58))
  176.                 {
  177.                     if (pos == end)
  178.                     {
  179. /*                        if (change == FALSE && pos>0)
  180.                         {
  181.                             cleft(pos);
  182.                             space(end);
  183.                             cleft(end);
  184.                             pos        = 1;
  185.                             end        = 1;
  186.                             bp[0]        = *cp;
  187.                             bp[1]        = 0;
  188.                             Writeio(cp,1);
  189.                         }
  190.                         else*/
  191.                         {
  192.                             if ((pos - start) < fieldlen)
  193.                             {
  194. //                                printf("if 1\n");
  195.                                 Writeio(cp,1);
  196.                             }
  197.                             else
  198.                             {
  199. //                                printf("if 2\n");
  200.                                 cleft(fieldlen);
  201.                                 Writeio(bp + start + 1,fieldlen);
  202.                                 Writeio(cp,1);
  203.                                 start++;
  204.                             }
  205.                             bp[pos] = *cp;
  206.                             pos++;
  207.                             end++;
  208.                             bp[end] = 0;
  209.                         }
  210.                     }
  211.                     else
  212.                     {
  213.                         if ((pos - start) == fieldlen)
  214.                         {
  215. //                            printf("if 3\n");
  216.                             cleft(fieldlen);
  217.                             Writeio(bp + start + 1,fieldlen - 1);
  218.                             Writeio(cp, 1);
  219.                             start++;
  220.                         }
  221.                         else
  222.                         {
  223.                             if (end > fieldlen)
  224.                             {
  225. //                                printf("if 4\n");
  226.                                 cleft((pos - start));
  227.                                 Writeio(bp + start,pos - start);
  228.                                 Writeio(cp,1);
  229.                                 Writeio(bp + start + (pos - start), fieldlen - (pos - start) - 1);
  230.                                 cleft((fieldlen - (pos - start)) -1);
  231.                             }
  232.                             else
  233.                             {
  234. //                                printf("if 5\n");
  235.                                 Writeio(cp,1);
  236.                         if ((end - pos) > fieldlen)
  237.                                 {
  238.                                     Writeio(bp + pos, fieldlen - (pos - start) - 1);
  239.                                     cleft((fieldlen - (pos - start)) -1);
  240.                                 }
  241.                                 else
  242.                                 {
  243.                            Writeio(bp + pos, end - pos - 1);
  244.                                     cleft(end - pos - 1);
  245.                                 }
  246.                             }
  247.                         }
  248.                         for (i = end ; i >= pos ; i--)
  249.                         {
  250.                             bp[i+1] = bp[i];
  251.                         }
  252.                         end++;
  253.                         bp[pos]    = *cp;
  254.                         bp[end]    = 0;
  255.                         pos++;
  256.                     }
  257.                     change    = TRUE;
  258.                     habschon    = TRUE;
  259.                     bp[end]    = 0;
  260.                 }
  261.             }
  262.             if (flags & CURSER_BREAK)
  263.                 Quit = TRUE;
  264. //            if (pos == 0 && end == 0) Quit = TRUE;
  265.         }
  266.         bp[end]=0;
  267.         bp[end+1]=0;
  268.     }
  269.     return result;
  270. }
  271.